﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using HammerMUD.System;
using HammerMUD.Commands;

namespace HammerMUD.Rooms
{
    public class NormalExit
    {
        public static String[] West = new String[] { "w", "west" };
        public static String[] East = new String[] { "e", "east" };
        public static String[] North = new String[] { "n", "north" };
        public static String[] South = new String[] { "s", "south" };
    }

    public class Exit
    {
        private Int64 from;
        private Int64 to;
        private List<String> names;

        public List<String> Names
        {
            get { return names; }
            set { names = value; }
        }

        public Int64 To
        {
            get { return to; }
            set { to = value; }
        }

        public Int64 From
        {
            get { return from; }
            set { from = value; }
        }

        internal static Boolean ParseExit(List<String> arguments, User user)
        {
            String exitName;
            if (arguments[0].ToLower().Equals("go") || arguments[0].ToLower().Equals("enter"))
            {
                exitName = arguments[1].ToLower();
            }
            else
            {
                exitName = arguments[0].ToLower();
            }

            foreach (Exit e in user.UserAccount.CurrentCharacter.CurrentRoom.Exits)
            {
                if (e.Names.Contains(exitName)
                        && e.From.Equals(user.UserAccount.CurrentCharacter.CurrentRoom.RoomNumber))
                {
                    RoomUtilities.SendToRoom(user, user.UserAccount.CurrentCharacter.Name + " leaves");
                    user.UserAccount.CurrentCharacter.Move(RoomUtilities.FindRoom(e.To));
                    RoomUtilities.SendToRoom(user, user.UserAccount.CurrentCharacter.Name + " arrives");
                    LookCommand.DoLook(user);
                    return true;
                }
            }

            return false;
        }
    }
}
